home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / CONSTRAI / STD_OBJP.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  9.8 KB  |  282 lines

  1.  
  2. package sub_arctic.constraints;
  3.  
  4. import sub_arctic.lib.interactor_consts;
  5. import sub_arctic.lib.interactor;
  6.  
  7. /** 
  8.  * Class to provide a standard object/part encoding and to provide constants 
  9.  * for them that can be used to build constraints.  These references can 
  10.  * denote standard parts within the local neighborhood of an object and 
  11.  * can be used as part of lightweight constraints that use minimal storage
  12.  * (which are the default).  These lightweight references are encoded in 6 
  13.  * bits: depended upon objects are encoded in 3 (high order) bits and parts 
  14.  * use another 3 (stored in the low order bits).  In addition, lightweight 
  15.  * references store an orientation for type checking purposes.<p>
  16.  * 
  17.  * Methods are provided for creating a new instance from an existing instance 
  18.  * by filling in the part portion only.  This allows several of  these objects 
  19.  * (i.e., PARENT) to be used as "constant factories" so we get  a cleaner 
  20.  * notation (i.e., PARENT.W()).
  21.  *
  22.  * @author Scott Hudson
  23.  */
  24.  
  25. public class std_objpart_encoding implements std_encoding_consts {
  26.  
  27.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  28.  
  29.   /** The encoding of the object and part for local object references and 
  30.    *  standard parts.  This is encoded in 6 bits with the high 3 being an 
  31.    *  object reference code and the low 3 being a part designator code.  */
  32.   protected int _encoding = 0;
  33.  
  34.   /** The encoding of the object and part for local object references and 
  35.    *  standard parts.  This is encoded in 6 bits with the high 3 being an 
  36.    *  object reference code and the low 3 being a part designator code.  */
  37.   public int encoding() {return _encoding;}
  38.  
  39.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  40.  
  41.   /** The orientation of this part.  This should be one of the values: 
  42.    *  std_encoding_consts.HORIZONTAL, std_encoding_consts.VERTICAL, or 
  43.    *  std_encoding_consts.NOT_ORIENTED. */
  44.   protected int _orientation;
  45.  
  46.   /** The orientation of this part.  This should be one of the values: 
  47.    *  std_encoding_consts.HORIZONTAL, std_encoding_consts.VERTICAL, or 
  48.    *  std_encoding_consts.NOT_ORIENTED. */
  49.   public int orientation() {return _orientation;}
  50.  
  51.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  52.  
  53.   /** 
  54.    * Constructor for a local reference to a standard part.  
  55.    * 
  56.    * @param int obj_code    value for object encoding.  This must be between
  57.    *                        zero and OBJCODE_MAX.  Values outside this range
  58.    *                        will be silently truncated.
  59.    * @param int part_code   value for part encoding.  This must be between
  60.    *                        zero and PARTCODE_MAX.  Values outside this range
  61.    *                        will be silently truncated.
  62.    * @param int orient_code code for the orientation of this part.  Should be 
  63.    *                        one of HORIZONTAL, VERTICAL, or NOT_ORIENTED
  64.    */
  65.   public std_objpart_encoding(int obj_code, int part_code, int orient_code)
  66.     {
  67.       _encoding = ((obj_code & OBJCODE_MASK) << OBJCODE_SHIFT) | 
  68.               ((part_code & PARTCODE_MASK) << PARTCODE_SHIFT);
  69.       _orientation = orient_code;
  70.     }
  71.  
  72.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  73.  
  74.   /** Extract and return just the object designator encoding */
  75.   public int object_encoded() 
  76.     {
  77.       return (_encoding >> OBJCODE_SHIFT) & OBJCODE_MASK;
  78.     }
  79.  
  80.   /** Extract and return just the object designator from the given encoding */
  81.   public static int object_encoded(int enc) 
  82.     {
  83.       return (enc >> OBJCODE_SHIFT) & OBJCODE_MASK;
  84.     }
  85.     
  86.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  87.  
  88.   /** Extract and return just the part designator encoding */
  89.   public int part_encoded() 
  90.     {
  91.       return (_encoding >> PARTCODE_SHIFT) & PARTCODE_MASK;
  92.     }
  93.  
  94.   /** Extract and return just the part designator from the given encoding */
  95.   public static int part_encoded(int enc) 
  96.     {
  97.       return (enc >> PARTCODE_SHIFT) & PARTCODE_MASK;
  98.     }
  99.     
  100.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  101.  
  102.   /** Method returning an instance designating the x part of this object */
  103.   public std_objpart_encoding X() 
  104.     {
  105.       return new std_objpart_encoding(object_encoded(), PARTCODE_XY,HORIZONTAL);
  106.     }
  107.  
  108.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  109.  
  110.   /** Method returning an instance designating the x1 part of this object.
  111.    *  This does exactly the same thing as X(). */
  112.   public std_objpart_encoding X1() 
  113.     {
  114.       return X();
  115.     }
  116.  
  117.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  118.  
  119.   /** Method returning an instance designating the left part of this object.
  120.    *  This does exactly the same thing as X(). */
  121.   public std_objpart_encoding LEFT() 
  122.     {
  123.       return X();
  124.     }
  125.  
  126.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  127.  
  128.   /** Method returning an instance designating the y part of this object */
  129.   public std_objpart_encoding Y() 
  130.     {
  131.       return new std_objpart_encoding(object_encoded(), PARTCODE_XY, VERTICAL);
  132.     }
  133.  
  134.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  135.  
  136.   /** Method returning an instance designating the y1 part of this object.
  137.    *  This does the exactly the same thing as Y(). */
  138.   public std_objpart_encoding Y1() 
  139.     {
  140.       return Y();
  141.     }
  142.  
  143.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  144.  
  145.   /** Method returning an instance designating the top part of this object.
  146.    *  This does the exactly the same thing as Y(). */
  147.   public std_objpart_encoding TOP() 
  148.     {
  149.       return Y();
  150.     }
  151.  
  152.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  153.  
  154.   /** Method returning an instance designating the x2 part of this object */
  155.   public std_objpart_encoding X2() 
  156.     {
  157.       return new std_objpart_encoding(object_encoded(),PARTCODE_XY2,HORIZONTAL);
  158.     }
  159.  
  160.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  161.  
  162.   /** Method returning an instance designating the right part of this object. 
  163.    *  This is the same as X2(). */
  164.   public std_objpart_encoding RIGHT() 
  165.     {
  166.       return X2();
  167.     }
  168.  
  169.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  170.  
  171.   /** Method returning an instance designating the y2 part of this object */
  172.   public std_objpart_encoding Y2() 
  173.     {
  174.       return new std_objpart_encoding(object_encoded(), PARTCODE_XY2, VERTICAL);
  175.     }
  176.  
  177.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  178.  
  179.  
  180.   /** Method returning an instance designating the bottom part of this object.
  181.    *  This is the same as Y2(). */
  182.   public std_objpart_encoding BOTTOM() 
  183.     {
  184.       return Y2();
  185.     }
  186.  
  187.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  188.  
  189.   /** Method returning an instance designating the w part of this object */
  190.   public std_objpart_encoding W() 
  191.     {
  192.       return new std_objpart_encoding(object_encoded(), PARTCODE_WH,HORIZONTAL);
  193.     }
  194.  
  195.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  196.  
  197.   /** Method returning an instance designating the h part of this object */
  198.   public std_objpart_encoding H() 
  199.     {
  200.       return new std_objpart_encoding(object_encoded(), PARTCODE_WH, VERTICAL);
  201.     }
  202.  
  203.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  204.  
  205.   /** Method returning an instance designating the horizontal center part of 
  206.    *  this object */
  207.   public std_objpart_encoding HCENTER() 
  208.     {
  209.       return new std_objpart_encoding(object_encoded(), PARTCODE_CENTER, 
  210.                                    HORIZONTAL);
  211.     }
  212.  
  213.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  214.  
  215.   /** Method returning an instance designating the vertical center part of 
  216.    *  this object */
  217.   public std_objpart_encoding VCENTER() 
  218.     {
  219.       return new std_objpart_encoding(object_encoded(), PARTCODE_CENTER, 
  220.                                      VERTICAL);
  221.     }
  222.  
  223.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  224.  
  225.   /** Method returning an instance designating the "visible" part of this 
  226.    *  object */
  227.   public std_objpart_encoding VISIBLE() 
  228.     {
  229.       return new std_objpart_encoding(object_encoded(), PARTCODE_VISIBLE, 
  230.                                  NOT_ORIENTED);
  231.     }
  232.  
  233.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  234.  
  235.   /** Method returning an instance designating the "enabled" part of this 
  236.    *  object */
  237.   public std_objpart_encoding ENABLED() 
  238.     {
  239.       return new std_objpart_encoding(object_encoded(), PARTCODE_ENABLED, 
  240.                                  NOT_ORIENTED);
  241.     }
  242.  
  243.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  244.  
  245.   /** Method returning an instance designating the "part_a" part of this 
  246.    *  object. */
  247.   public std_objpart_encoding PART_A() 
  248.     {
  249.       return new std_objpart_encoding(object_encoded(), PARTCODE_PART_A, 
  250.                                  NOT_ORIENTED);
  251.     }
  252.  
  253.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  254.  
  255.   /** Method returning an instance designating the "part_b" part of this 
  256.    *  object. */
  257.   public std_objpart_encoding PART_B() 
  258.     {
  259.       return new std_objpart_encoding(object_encoded(), PARTCODE_PART_B, 
  260.                                  NOT_ORIENTED);
  261.     }
  262.  
  263.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  264. }
  265.  
  266. /*=========================== COPYRIGHT NOTICE ===========================
  267.  
  268. This file is part of the subArctic user interface toolkit.
  269.  
  270. Copyright (c) 1996 Scott Hudson and Ian Smith
  271. All rights reserved.
  272.  
  273. The subArctic system is freely available for most uses under the terms
  274. and conditions described in 
  275.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  276. and appearing in full in the lib/interactor.java source file.
  277.  
  278. The current release and additional information about this software can be 
  279. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  280.  
  281. ========================================================================*/
  282.